<template>
	<view class="container">
		<view class="head">
			<u-icon @click="returnButton()" name="arrow-left" color="#fff" size="30"></u-icon>
			<u-text text="附近门店" color="#fff" size="22" align="center" margin="4vh 0px 0px 0px"></u-text>
			<view class="search">
				<view class="info">
					<input placeholder="请输入要搜索内容" />
					<image src="@/static/images/ls/搜索@3x.png"></image>
				</view>
				<view class="record">
					<text class="title">历史记录：</text>
					<text class="item">飞飞汽修美容店</text>
				</view>
			</view>
		</view>
		<view class="head-2">
		</view>

		<view v-for="(item,index) in shopInfoList" :key="index">
			<view class="content" @click="toDetail(item.id)">
				<view class="line1">
					<view>
						{{item.name}}
					</view>
					<view>
						{{item.lon_lat}}m
					</view>
				</view>

				<view style="display: flex;margin-top: 1vh;">
					<uni-rate :readonly="true" size="20" :value="item.star" />
					<view style="margin-left: 5vw;">销量：{{item.sales}}</view>
				</view>

				<view class="line2">
					<view class="lineright">
						<image src="@/static/images/ls/服务站.jpg" style="height: 12vh;width: 28vw; border-radius: 15rpx;">
						</image>
					</view>
					<view class="lineleft">
						<view>
							营业时间：{{item.week}}
						</view>
						<view>
							早上{{item.start_time}}-晚上{{item.end_time}}
						</view>
						<view>
							位置：{{item.address}}{{item.area}}
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
	</view>
</template>

<script>
	import tabbar from '../../../uni_modules/uview-ui/libs/config/props/tabbar';
	export default {
		data() {
			return {
				shop_id: 1,
				shopInfoList: [{
					lon_lat: 0
				}],
				longitude: 0,
				latitude: 0
			}
		},
		methods: {
			// 获取商家信息
			getNotice() {
				let that = this;
				this.$http({
					url: '/api/shop/manage/list',
					method: 'GET',
					success(res) {
						if (!res.data.rows) {
							console.log(res)
							return;
						}
						that.shopInfoList = res.data.rows;
						// console.log(that.shopInfoList)
						that.shopInfoList.forEach((item) => {
							if (item.latitude && item.longitude)
								item.lon_lat = that.getLat_Lon(that.latitude, that.longitude,
									item.latitude, item.longitude)
						})
					}
				});
			},

			// 获取当前位置
			getNowAddress() {
				let that = this
				uni.getLocation({
					type: 'gps',
					success: function(res) {
						that.latitude = res.latitude
						that.longitude = res.longitude
						// console.log('当前位置的经度：' + that.longitude);
						// console.log('当前位置的纬度：' + that.latitude);
					},
					fail: function(err) {
						console.error('获取位置失败：', err);
					}
				});
			},
			// 计算距离
			getLat_Lon(lat1, lon1, lat2, lon2) { //计算两点之间的距离
				// console.log('nowlat' + lat1 + 'nowlong' + lon1 + '------tolat' + lat2 + 'tolong' + lon2)
				let R = 6371; //地球半径
				let dLat = this.deg2rad(lat2 - lat1)
				let dLon = this.deg2rad(lon2 - lon1)
				let a =
					Math.sin(dLat / 2) * Math.sin(dLat / 2) +
					Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) *
					Math.sin(dLon / 2) * Math.sin(dLon / 2);
				let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
				let d = R * c; // 距离，单位：千米  
				let e = parseFloat(d)
				let f = e.toFixed(2)
				return f;
			},
			deg2rad(deg) {
				return deg * (Math.PI / 180)
			},

			returnButton() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			toDetail(shop_id) { // 详情
				uni.redirectTo({
					url: '/pages/ls/carWash/carWash?shop_id=' + shop_id
				})
			}
		},
		onLoad(options) {
			if (options.shop_id) this.shop_id = options.shop_id;
			this.getNowAddress();
			this.getNotice();
		}
	}
</script>

<style lang="scss">
	.search {
		// background-color: rebeccapurple;
		width: 100%;
		height: 10vh;
		position: fixed;
		top: 11vh;
		box-sizing: border-box;
		padding: 0rpx 25rpx;

		.record {
			box-sizing: border-box;
			padding: 0rpx 25rpx;

			.title {
				color: white;
				font-size: 35rpx;
				line-height: 60rpx;
			}

			.item {
				color: white;
			}
		}


		.info {
			background-color: #f7f7f7;
			width: 100%;
			height: 7vh;
			border-radius: 50rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
			padding: 0 30rpx;

			image {
				height: 6vw;
				width: 6vw;
			}
		}
	}

	.content {
		height: 30vh;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		padding: 30rpx 25rpx;
		background-color: white;
		width: 90vw;
		margin: 0 auto;
		margin-bottom: 2vh;
		transform: translateY(27vh);
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 6px 20px rgba(0, 0, 0, 0.1);
		border-radius: 16rpx;

		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 2vh;
		}

		.title>text:nth-child(1) {
			font-size: 18px;
			font-weight: 600;
		}

		.title>text:nth-child(2) {
			font-size: 13px;
			color: #3183FB;
		}

	}

	.head-2 {
		position: absolute;
		background-color: #3183FB;
		width: 100%;
		height: 32vh;
		overflow: auto;
		z-index: 0;
	}

	.head {
		position: fixed;
		background-color: #3183FB;
		width: 100%;
		height: 27vh;
		overflow: auto;
		z-index: 3;

		.u-icon {
			position: fixed;
			top: 4vh;
		}
	}


	.line1 {
		margin-top: 2vh;
		display: flex;
		justify-content: space-between;
	}

	.line1 :nth-child(1) {
		font-size: 3vh;
		font-weight: 600;
	}

	.line1 :nth-child(2) {
		color: #2F81FA;
	}

	.lineright {
		padding-top: 1vh;
		/* padding-left: 2vw; */
		box-sizing: border-box;
	}

	.line2 {
		display: flex;
	}

	.lineleft {
		margin-left: 2vw;
		margin-top: 1vh;
		text-align: left;
		font-size: 25rpx;
		line-height: 50rpx;
	}
</style>